#!/bin/sh

DIR=$(cd $(dirname "$0")/../..; pwd)
cd "$DIR"

set -ex

type gobump >/dev/null || go install github.com/x-motemen/gobump/cmd/gobump@latest
type ghr >/dev/null    || go install github.com/tcnksm/ghr@latest
type ghch >/dev/null   || go install github.com/Songmu/ghch/cmd/ghch@latest

APPLICATION='fireworq'
VERSION=$(gobump show -r)
DIST="dist/v$VERSION"

build() {
    os="$1"
    arch="$2"
    GOOS="$os" GOARCH="$arch" script/docker/build
    filename="${APPLICATION}_${os}_${arch}.zip"
    [ -f "$APPLICATION" ] || {
        echo "File missing: $APPLICATION" >&2
        exit 1
    }
    zip "$DIST/$filename" "$APPLICATION" README.md doc/* doc/*/* AUTHORS.md AUTHORS LICENSE CREDITS
}

mkdir -p "$DIST"
build linux amd64
build darwin amd64

ghr -u fireworq -r "$APPLICATION" -b "$(ghch --latest --format=markdown)" "v$VERSION" "$DIST"
